package com.zondy.mapgis.psmap.manager.controller;

import com.zondy.mapgis.common.controllerprefix.annotation.ManagerRestController;
import com.zondy.mapgis.common.core.utils.poi.ExcelUtil;
import com.zondy.mapgis.common.core.web.controller.BaseController;
import com.zondy.mapgis.common.core.web.domain.AjaxResult;
import com.zondy.mapgis.common.core.web.page.TableDataInfo;
import com.zondy.mapgis.common.log.annotation.Log;
import com.zondy.mapgis.common.log.enums.BusinessType;
import com.zondy.mapgis.common.security.annotation.RequiresPermissions;
import com.zondy.mapgis.common.security.utils.SecurityUtils;
import com.zondy.mapgis.domain.psmap.AppMapSheet;
import com.zondy.mapgis.psmap.manager.service.IAppMapSheetService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Tag(
   name = "图幅信息管理",
   description = "图幅信息控制器"
)
@ManagerRestController({"/app/mapSheet"})
public class AppMapSheetController extends BaseController {
   @Autowired
   private IAppMapSheetService appMapSheetService;

   @Operation(
      summary = "查询图幅信息列表"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:list')")
   @RequiresPermissions({"app:sheet:list"})
   @GetMapping({"/list"})
   public TableDataInfo list(AppMapSheet appMapSheet) {
      this.startPage();
      List<AppMapSheet> list = this.appMapSheetService.selectAppMapSheetList(appMapSheet);
      return this.getDataTable(list);
   }

   @Operation(
      summary = "查询比例尺列表"
   )
   @GetMapping({"/scaleList"})
   public TableDataInfo selectAppMapSheetScaleList(@RequestParam String rect, @RequestParam String originSrs, @RequestParam String destSrs) {
      this.startPage();
      List<String> scaleList = this.appMapSheetService.selectAppMapSheetScaleList(rect, originSrs, destSrs);
      return this.getDataTable(scaleList);
   }

   @Operation(
      summary = "查询图幅：自动缓存"
   )
   @GetMapping({"/no"})
   public TableDataInfo queryNos(@RequestParam String scale, @RequestParam String rect, @RequestParam String originSrs, @RequestParam String destSrs, @RequestParam String gdbp, @RequestParam String url, @RequestParam(defaultValue = "") String keyword, @RequestParam(defaultValue = "0") int pageNum, @RequestParam(defaultValue = "20") int pageSize, @RequestParam(defaultValue = "false") Boolean replace) {
      return this.appMapSheetService.queryNos(scale, rect, originSrs, destSrs, gdbp, url, keyword, pageNum, pageSize, replace);
   }

   @Operation(
      summary = "导出图幅信息列表"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:export')")
   @RequiresPermissions({"app:sheet:export"})
   @Log(
      title = "图幅信息",
      businessType = BusinessType.EXPORT
   )
   @PostMapping({"/export"})
   public void export(HttpServletResponse response, AppMapSheet appMapSheet) {
      List<AppMapSheet> list = this.appMapSheetService.selectAppMapSheetList(appMapSheet);
      ExcelUtil<AppMapSheet> util = new ExcelUtil<>(AppMapSheet.class);
      util.exportExcel(response, list, "图幅信息数据");
   }

   @Operation(
      summary = "获取图幅信息详细信息"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:query')")
   @RequiresPermissions({"app:sheet:query"})
   @GetMapping({"/{mapSheetId}"})
   public AjaxResult getInfo(@PathVariable("mapSheetId") Long mapSheetId) {
      return this.success(this.appMapSheetService.selectAppMapSheetByMapSheetId(mapSheetId));
   }

   @Operation(
      summary = "新增图幅信息"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:add')")
   @RequiresPermissions({"app:sheet:add"})
   @Log(
      title = "图幅信息",
      businessType = BusinessType.INSERT
   )
   @PostMapping
   public AjaxResult add(@RequestBody AppMapSheet appMapSheet) {
      appMapSheet.setCreateBy(SecurityUtils.getUsername());
      return this.toAjax(this.appMapSheetService.insertAppMapSheet(appMapSheet));
   }

   @Operation(
      summary = "修改图幅信息"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:edit')")
   @RequiresPermissions({"app:sheet:edit"})
   @Log(
      title = "图幅信息",
      businessType = BusinessType.UPDATE
   )
   @PutMapping
   public AjaxResult edit(@RequestBody AppMapSheet appMapSheet) {
      appMapSheet.setUpdateBy(SecurityUtils.getUsername());
      return this.toAjax(this.appMapSheetService.updateAppMapSheet(appMapSheet));
   }

   @Operation(
      summary = "删除图幅信息"
   )
   @PreAuthorize("@ss.hasPermi('app:sheet:remove')")
   @RequiresPermissions({"app:sheet:remove"})
   @Log(
      title = "图幅信息",
      businessType = BusinessType.DELETE
   )
   @DeleteMapping({"/{mapSheetIds}"})
   public AjaxResult remove(@PathVariable Long[] mapSheetIds) {
      return this.toAjax(this.appMapSheetService.deleteAppMapSheetByMapSheetIds(mapSheetIds));
   }
}
